package com.hsr.web.controller;


import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
import com.hsr.web.dto.CarouselDTO;
import com.hsr.web.dto.FileDTO;
import com.hsr.web.dto.FileQuery;
import com.hsr.web.entity.TCarousel;
import com.hsr.web.entity.TFile;
import com.hsr.web.service.ITCarouselService;
import com.hsr.web.utils.ResultVOUtil;
import com.hsr.web.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tb
 * @since 2022-04-05
 */
@Api(tags = "首页图片轮播")
@RestController
@RequestMapping("/carousel")
@Slf4j
public class TCarouselController {

    @Autowired
    private ITCarouselService carouselService;

    @GetMapping("/list")
    @ApiOperation("查询所有图片")
    public ResultVO list() {
        return ResultVOUtil.success(carouselService.list());
    }

    @PutMapping
    @ApiOperation("新增")
    public ResultVO insert(@RequestBody CarouselDTO carouselDTO){
        TCarousel carousel = new TCarousel();
        BeanUtils.copyProperties(carouselDTO,carousel);
        carouselService.save(carousel);
        return ResultVOUtil.success();
    }

    @PutMapping("/{id}")
    @ApiOperation("编辑")
    public ResultVO update(@RequestBody CarouselDTO carouselDTO,@PathVariable String id){
        carouselDTO.setId(id);
        TCarousel carousel = new TCarousel();
        BeanUtils.copyProperties(carouselDTO,carousel);
        carouselService.updateById(carousel);
        return ResultVOUtil.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public ResultVO delete(@PathVariable String id){
        carouselService.removeById(id);
        return ResultVOUtil.success();
    }

}
